/***************************************************************************//**
 * @file CGI/CGI_Manager.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef CGI_MANAGER_H
#define CGI_MANAGER_H

////////////////////////////////////////////////////////////////////////////////

#include "CamManipulatorExternal.h"
#include "CamManipulatorInternal.h"

#include "CGI_Data.h"

#include "SceneRoot.h"

////////////////////////////////////////////////////////////////////////////////

/** */
class CGI_Manager
{
public:

    /** Constructor. */
    CGI_Manager();

    /** Destructor. */
    virtual ~CGI_Manager();

    /** */
    void update( double timeStep, const CGI_DataInp &dataInp, CGI_DataOut &dataOut );

    /** */
    inline osg::ref_ptr<osgGA::CameraManipulator> getCameraManipulator()
    {
        switch ( m_camManipulatorType )
        {
            case InternalCamManipulator: return m_camManipulatorInternal; break;
            case ExternalCamManipulator: return m_camManipulatorExternal; break;
        }

        return m_camManipulatorInternal;
    }

    /** */
    inline osg::ref_ptr<osg::Group> getSceneRoot()
    {
        return m_sceneRoot->getSceneRoot();
    }

    /** */
    inline void setInternalCameraManipulator()
    {
        m_camManipulatorType = InternalCamManipulator;
    }

    /** */
    inline void setExternalCameraManipulator()
    {
        setTrackNode( m_camManipulatorExternal.get() );
        m_camManipulatorType = ExternalCamManipulator;
    }

private:

    /** */
    enum CameraManipulatorType
    {
        InternalCamManipulator = 0x1,   ///<
        ExternalCamManipulator = 0x2    ///<
    };

    CGI_Data *m_data;

    SceneRoot *m_sceneRoot; ///<

    osg::ref_ptr<CamManipulatorInternal> m_camManipulatorInternal;
    osg::ref_ptr<CamManipulatorExternal> m_camManipulatorExternal;

    CameraManipulatorType m_camManipulatorType;

    /** Using this constructor is forbidden. */
    CGI_Manager( const CGI_Manager & ) {}

    /** */
    void setTrackNode( osgGA::NodeTrackerManipulator *nodeTrackerManipulator );
};

////////////////////////////////////////////////////////////////////////////////

#endif // CGI_MANAGER_H
